//
//  CAIPHPickerControllerManager.h
//  CAIImagePickerController_Example
//
//  Created by 海参 on 2022/7/14.
//  Copyright © 2022 海参. All rights reserved.
//
//  简介： UIImagePickerViewController 功能受限，每次只能选择一张图片，将逐渐被废弃。
//  PHPicker 支持多选，支持搜索，支持按image，video，livePhotos 等进行选择。
//  注意：PHImagePickerController和UIImagePickerController一样，不需要请求访问相册权限，就可以访问到相册全部内容；

#import <Foundation/Foundation.h>
#import <PhotosUI/PhotosUI.h>
#import "CAIImagePickerManagerErrorConst.h"


NS_ASSUME_NONNULL_BEGIN


/// 默认允许选择图片，不允许选择视频；默认选择数量是1；
@interface CAIPHPickerConfiguration : NSObject <NSCopying>

/// Maximum number of assets that can be selected. Default is 1.
/// @discussion Setting \c selectionLimit to 0 means maximum supported by the system.
@property (NS_NONATOMIC_IOSONLY) NSInteger selectionLimit;

/// 默认为NO，如果设置为NO,用户将不能选择视频
@property (nonatomic, assign) BOOL allowPickingVideo;

/// 默认为YES，如果设置为NO,用户将不能选择图片;不能同时设置allowPickingVideo、allowPickingImage为NO，必须支持其一；
@property (nonatomic, assign) BOOL allowPickingImage;


@end



@class CAIPHPickerControllerManager;
@protocol CAIPHPickerControllerManagerDelegate <NSObject>


/// 完成调用后的回调；成功获取图片或者失败获取图片后的回调；
/// @param photos 选择之后的图片，取消的话不反回；
/// @param error 各种异常信息，包括没有权限，取消使用；
- (void)imagePickerControllerManager:(CAIPHPickerControllerManager *)manager
     didFinishPickingMediaWithPhotos:(nullable NSArray<UIImage *> *)photos
                               error:(nullable NSError *)error;

@end


API_AVAILABLE(ios(14)) @interface CAIPHPickerControllerManager : NSObject<PHPickerViewControllerDelegate>


@property(nonatomic, weak) id <CAIPHPickerControllerManagerDelegate> delegate;

@property(nonatomic, strong) CAIPHPickerConfiguration *pickerConfiguration;



/// 弹出相册选择-选择图片
/// @param viewController presentingViewController
/// @param delegate 代理
- (void)showImagePickerWithFromViewController:(UIViewController *)viewController
                                     delegate:(id)delegate;



/// 弹出相册选择-选择图片或视频
/// @param viewController viewController description
/// @param delegate delegate description
/// @param selectionLimit 限制选择数量
/// @param allowPickingImage 是否允许选择图片
/// @param allowPickingVideo 是否允许选择视频
- (void)showImagePickerWithFromViewController:(UIViewController *)viewController
                                     delegate:(id)delegate
                               selectionLimit:(NSInteger)selectionLimit
                            allowPickingImage:(BOOL)allowPickingImage
                            allowPickingVideo:(BOOL)allowPickingVideo;

/// 根据配置对象弹出相册选择
/// @param viewController viewController description
/// @param delegate delegate description
/// @param configuration 配置对象
- (void)showImagePickerWithFromViewController:(UIViewController *)viewController
                                     delegate:(id)delegate
                                 configuraton:(nullable CAIPHPickerConfiguration *)configuration;



@end

NS_ASSUME_NONNULL_END
